﻿<html>

	<head>
		<title>权限管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
		<link href="../../css/dialog.css" rel="stylesheet">

		<script type="text/javascript" src="../../js/lib/jquery/jquery-1.10.2.min.js"></script>

		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
		<script src="../../js/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js?version=20180420" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		<style>
			a:hover {
				cursor: pointer;
			}
		</style>
		<script type="text/javascript">
			var manager, detailManager, rolemanager, momanager; //表格
			$(document).hover(parent.hindMenu);
			document.oncontextmenu = stop;

			function stop() {
				return false;
			}
			var token = $api.getStorage("token");
			var SysRole = BaseUrl + "SysRole?token=" + token;
			//角色附加权限
			var SysMenuDetail = BaseUrl + "SysMenuDetail";
			var SysMenu = BaseUrl + "SysMenu?token=" + token;

			$(function() {
				document.body.oncontextmenu = function rightClick() {
					window.event.returnValue = false;
				}

				initGridRole();
				initTreeMenu();
				initGrid();
				initGridDetail();
			});
			var roleid = 1;
			var mid = 1000;
			var mid2 = 1010;
			////////////初始化//////////////////////////////////////////////////

			//初始化角色
			function initGridRole() {
				var url = SysRole;
				rolemanager = $("#menurole").ligerGrid({
					columns: [{
							display: '角色',
							name: 'RoleName',
							width: 120,
							align: 'center'
						},
						{
							display: '操作',
							name: 'handle',
							minwidth: 60,
							align: 'center',
							render: function(item, rowindex, value) {
								return "<a   onclick='delRole(" + rowindex + ");'>删除</a>";
							}
						}
					],
					dataAction: 'local',
					url: url,
					method: 'get',
					width: 228,
					height: 372,
					usePager: false,
					rowHeight: 33,
					rownumbers: false,
					checkbox: false,
					onSelectRow: function(rowdata, rowid, rowobj) {
						roleid = rowdata.RoleId;
						f_reload();
						f_detailonload();

					}
				});

			}
			//主菜单

			function initTreeMenu() {
				var url = SysMenu + "&pid=0&roleid=" + roleid;
				momanager = $("#menuogrid").ligerGrid({
					columns: [{
						display: '菜单',
						name: 'MenuName',
						minWidth: 180,
						align: 'center'
					}],
					method: 'get',
					dataAction: 'local',
					url: url,
					width: 228,
					height: 372,
					usePager: false,
					rownumbers: false,
					checkbox: false,
					onSelectRow: function(rowdata, rowid, rowobj) {
						mid = rowdata.MenuId;
						f_reload();
						f_detailonload();
					}
				});
			}
			//子菜单
			function initGrid() {
				var url = "";
				manager = $("#maingrid").ligerGrid({
					columns: [{
							display: '模块名称',
							name: 'MenuName',
							width: 180,
							align: 'center'
						},
						{
							display: '有否权限',
							name: 'IsSelect',
							minwidth: 70,
							render: function(item, rowindex, value) {
								var html = "<div style='margin-top:5px;'><input type='checkbox' style='height:15px;width:15px' ";
								if(0 == roleid || 1 == roleid)
									html += " onclick='return false';disabled='disabled'  ";
								else
									html += " onclick = 'changeMenu(" + rowindex + ",this)' ";
								if(item.IsSelect == true) {
									html += "checked='checked' ";
								} else html += " /></div>";
								return html;
							}
						}
					],
					dataAction: 'local',
					url: url,
					method: 'get',
					width: 318,
					height: 260,
					rowHeight: 33,
					usePager: false,
					rownumbers: true,
					checkbox: false,
					onLoaded: setTimeout(f_detailonload, 300),
					onSelectRow: function(rowdata, rowid, rowobj) {
						mid2 = rowdata.MenuId;
						menu2 = rowdata;
						f_detailonload();
					}

				});

			}
			var menu2;
			//附加权限
			function initGridDetail() {
				var url = "";
				detailManager = $("#detailgrid").ligerGrid({
					columns: [{
							display: '明细权限',
							name: 'Name',
							width: 180,
							align: 'center'
						},
						{
							display: '有否权限',
							name: 'IsSelect',
							minwidth: 70,
							render: function(item, rowindex, value) {
								var html = "<div style='margin-top:5px;'><input type='checkbox' style='height:15px;width:15px'  ";

								if(0 == roleid || 1 == roleid || $api.isEmpty(menu2) || menu2.IsSelect == false)
									html += " onclick='return false';disabled='disabled'  ";
								else
									html += " onclick = 'changeMenuDetail(" + rowindex + ",this)' ";
								if(item.IsSelect == true) {
									html += "checked='checked' ";
								} else html += " /></div>";
								return html;
							}
						}
					],
					dataAction: 'local',
					url: url,
					method: 'get',
					width: 318,
					rowHeight: 33,
					height: 180,
					usePager: false,
					rownumbers: true

				});
			}
			///////////////////////////////////////////////////////////////////////////
			function f_reload() {
				var url = SysMenu + "&pid=" + mid + "&roleid=" + roleid;
				manager.GetDataByURL(url);
			}

			function f_detailonload() {
				var url = SysMenuDetail + "?token=" + token + "&mid=" + mid2 + "&roleid=" + roleid;
				detailManager.GetDataByURL(url);
			}

			function changeMenuDetail(rowindex, check) {
				var row = detailManager.getRow(rowindex);
				var param = {
					"Roleid": roleid,
					"Mlid": row.MLID,
					"Isselect": check.checked ? 1 : 0,
					"Token": token
				}

				$api.ajax2(SysMenuDetail, param, function(data) {
					f_detailonload();
				});

			}

			function changeMenu(rowindex, check) {
				var row = manager.getRow(rowindex);

				var param = {
					"Roleid": roleid,
					"Menuid": row.MenuId,
					"Isselect": check.checked ? 1 : 0,
					"Token": token
				}
				var url = BaseUrl + "SysMenu";

				$api.ajax2(url, param, function(data) {

					f_detailonload();
					menu2.IsSelect = check.checked;
				});

			}

			////////////事件角色////////////////////////////////////////////////////////
			function editRole(i) {
				var row = rolemanager.getRow(i);
				addRole(row);
			}

			function delRole(i) {
				var row = rolemanager.getRow(i);
				$.ligerDialog.confirm("角色删除后不能恢复，\n您确定要移除？", function(yes) {
					if(yes) {
						var url = SysRole + "&action=del";
						$api.ajax2(url, row, function(data) {
							role_reload();
						});
					}
				});
			}

			function addRole(row) {
				var url = 'vsys/sys_operator/AddRole.html';
				var title = '新增角色';
				if(!$api.isEmpty(row)) {
					url += '?data=' + escape(JSON.stringify(row));
					title = '修改角色';
				}
				var dialogOptions = {
					width: 410,
					height: 300,
					title: title,
					url: url,
					buttons: [{
							text: '保存',
							onclick: function(item, dialog) {
								f_save_role(item, dialog);
							}
						},
						{
							text: '关闭',
							onclick: function(item, dialog) {
								dialog.close();
							}
						}
					],
					isResize: true,
					timeParmName: 'a'
				};
				activeDialog = parent.jQuery.ligerDialog.open(dialogOptions);
			}

			function f_save_role(item, dialog) {
				var issave = dialog.frame.f_save();
				dialog.close();
				if(issave) {
					var url = SysRole;
					if(issave.action == "add") {
						issave.data.ParentID = 0;

						$api.ajax2(url, issave.data, function(data) {
							role_reload();
						});
					} else {
						url += "&action=edit";
						$api.ajaxput(url, issave.data, function(data) {
							role_reload();
						});
					}

				}
			}
			var role_reload = function() {
				rolemanager.GetDataByURL(SysRole);
			}
		</script>
	</head>

	<body>

		<form id="form1" onsubmit="return false">
			<div style="width: 790px;">
				<div class="toolbar-wrap">
					<div  class="toolbar">
						<div class="l-list">
							<ul style="margin-left: 5px;" id="icon-list" class="icon-list">
								<li>
									<a class='add' onclick='addRole();'><i></i><span>新增角色</span></a>
								</li>

							</ul>
						</div>

					</div>
				</div>
				<table>
					<tr>
						<td width="15%" height="100%">
							<div style="width:230px; height:372px; margin:3px; position: relative; border:1px solid #ccc; overflow:auto;  ">
								<div id="menurole"></div>
							</div>
						</td>
						<td width="15%" height="100%">
							<div style="width:230px; height:372px; margin:3px;position: relative; border:1px solid #ccc; overflow:auto;  ">
								<div id="menuogrid"></div>
							</div>
						</td>
						<td style="width:320px; height:100%; ">
							<div style="width:320px; height:372px; margin:3px;position: relative;   overflow:hidden;  ">

								<div  id="maingrid" ></div>

								<div id="detailgrid"></div>
							</div>
						</td>
					</tr>
					<tr>
						<td colspan="3">
							<div>
								<p style="font-size: 13px;">&nbsp;注：选择角色修改权限。权限修改后会立即保存，操作员再次登录时生效。</p>
							</div>

						</td>
					</tr>
				</table>

			</div>
		</form>

	</body>

</html>